package com.example.util;

import com.example.util.token.AuthenticationInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class WebMvcConfig  extends WebMvcConfigurationSupport {

    public String path = "D:\\ideaProject\\upload\\";
    @Resource
    private AuthenticationInterceptor authenticationInterceptor;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 上传路径映射 会使spring boot的自动配置失效
        registry.addResourceHandler("/thesis/**").addResourceLocations("file:" + path);
//        项目访问image路径会直接访问path路径下的文件
        super.addResourceHandlers(registry);
    }


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authenticationInterceptor)
                .addPathPatterns("/**");
    }

}